package cn.ztelovecly.springboot.framework.util.name;

/**
 *
 */
public class CompoundSurname {

    public static String[] SURNAME = {"欧阳", "太史", "端木", "上官", "司马", "东方", "独孤", "南宫", "万俟", "闻人", "夏侯", "诸葛", "尉迟", "公羊", "赫连", "澹台"
            , "皇甫", "宗政", "濮阳", "公冶", "太叔", "申屠", "公孙", "慕容", "仲孙", "钟离", "长孙", "宇文", "司徒", "鲜于", "司空", "闾丘", "子车", "亓官", "司寇", "巫马"
            , "公西", "颛孙", "壤驷", "公良", "漆雕", "乐正", "宰父", "谷梁", "拓跋", "夹谷", "轩辕", "令狐", "段干", "百里", "呼延", "东郭", "南门", "羊舌", "微生", "公户"
            , "公玉", "公仪", "梁丘", "公仲", "公上", "公门", "公山", "公坚", "左丘", "公伯", "西门", "公祖", "第五", "公乘", "贯丘", "公皙", "南荣", "东里", "东宫", "仲长"
            , "子书", "子桑", "即墨", "达奚", "褚师"};

    public static Name split(String nameStr) {
        if (nameStr == null || nameStr.length() == 0) {
            return null;
        }
        int strLength = nameStr.length();
        Name name = new Name();
        switch (strLength) {
            case 1:
                name.setFirstName(nameStr);
                break;
            case 2:
                name.setLastName(nameStr.substring(0, 1));
                name.setFirstName(nameStr.substring(1, 2));
                break;
            case 3:
                String lastName = nameStr.substring(0, 2);
                boolean flag = false;
                for (String str : SURNAME) {
                    if (str.equals(lastName)) {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    name.setLastName(lastName);
                    name.setFirstName(nameStr.substring(2, 3));
                } else {
                    name.setLastName(nameStr.substring(0, 1));
                    name.setFirstName(nameStr.substring(1, 3));
                }
                break;
            default:
                name.setLastName(nameStr.substring(0, strLength - 2));
                name.setFirstName(nameStr.substring(strLength - 2, strLength));
        }
        return name;
    }
}

